subBcd1   PROC NEAR32
; subtract 2 non-negative 10 byte packed BCD numbers
; parameter1:  address of operand1 (and destination)
; parameter2:  address of operand2
; operand1 - operand2  stored at destination
; author:  R. Detmer     revised: 5/98
          push ebp            ; establish stack frame
          mov  ebp, esp
          push esi            ; save registers
          push edi
          push ecx
          push eax
          mov  edi, [ebp+12]  ; destination address (operand 1)
          mov  esi, [ebp+8]   ; source address (operand 2)
          clc                 ; clear carry flag
          mov  ecx, 9         ; count of bytes to process
forSub:   mov  al, [edi]      ; get one operand byte
          sbb  al, [esi]      ; subtract other operand byte
          das                 ; adjust to BCD
          mov  [edi], al      ; save difference
          inc  edi            ; point at next operand bytes
          inc  esi
          loop forSub         ; repeat for all 9 bytes

          jnc  endIfBigger    ; done if destination >= source
          sub  edi, 9         ; point at beginning of destination
          mov  ecx, 9         ; count of bytes to process
forSub1:  mov  al, 0          ; subtract destination from zero
          sbb  al, [edi]
          das
          mov  [edi], al
          inc  edi            ; next byte
          loop forSub1
          mov  BYTE PTR [edi], 80h   ; negative result
endIfBigger:
          pop  eax            ; restore registers
          pop  ecx
          pop  edi
          pop  esi
          pop  ebp
          ret  8              ; return to caller
subBcd1   ENDP

